package edu.ubb.remeye.gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

/**
 * Panel for showing the image.
 * 
 * @author Andrew Ianicicau
 *
 */
public class ImagePanel extends JPanel {

	///////////////////////////////////////////////////////////////////////////////////
	////		ATTRIBUTES - ImagePanel
	///////////////////////////////////////////////////////////////////////////////////

	private static final long serialVersionUID = 1L;
	
	/**
	 * Image to draw.
	 */
	private BufferedImage desktopImage;

	
	
	///////////////////////////////////////////////////////////////////////////////////
	////		CONSTRUCTORS - ImagePanel
	///////////////////////////////////////////////////////////////////////////////////

	/**
	 * @param width The image width.
	 * @param height The image height.
	 */
	public ImagePanel(int width, int height) {
		super(true);
		setPreferredSize(new Dimension(width, height));
	}

	
	
	///////////////////////////////////////////////////////////////////////////////////
	////		METHODS - ImagePanel
	///////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * Override of paintComponent to draw image to panel.
	 * @param graphics The panel graphics object.
	 */
	@Override
	public void paintComponent(Graphics graphics) {
		super.paintComponent(graphics);
        graphics.drawImage(desktopImage, 0, 0, null);
	}
	
	/**
	 * Sets the image and calls repaint.
	 * @param image Image to use for repainting.
	 */
	public void drawDesktopImage(BufferedImage image) {
		desktopImage = image;
		this.repaint();
	}

}
